
# -*- coding: utf-8 -*-

from odoo import models, fields, api


class HrDepartment(models.Model):
    _inherit = 'hr.department'
    _rec_name='name'

    def get_parent_departments(self, parents=[]):
        if self.parent_id:
            parents.append(self.parent_id)
            return self.parent_id.get_parent_departments(parents)
        else:
            return parents

    def write(self, values):
        if 'manager_id' in values:
            for employee_id in self.member_ids:
                employee_id.parent_id=values['manager_id']
        return super(HrDepartment, self).write(values)


